import * as ACTION from '../actions/topAction';

export const DEFAULT_STATE = {
	title: '',
	message: '',
	messageType: ACTION.ENUM_INFO_TYPE.INFO,
	open: false
};

/**
 * 处理顶层消息
 * @param  {[type]} state  [description]
 * @param  {Object} action [description]
 * @return {[type]}        [description]
 */
export function topInfo(state = DEFAULT_STATE, action = {}) {
	let { type } = action;

	switch(type) {
		case ACTION.SET_TITLE:
			let { title } = action.payload;
			return Object.assign({}, state, { title }); 
		case ACTION.SEND_TOP_INFO:
			let { payload } = action;
			let { message = '', messageType = ACTION.ENUM_INFO_TYPE.INFO } = payload;
			return Object.assign({}, state, { message, messageType, open: true });
		case ACTION.CLOSE_TOP_INFO:
			return Object.assign({}, state, { open: false, message: '' });
		default:
			return state;
	}
};